package com.cn.mvc.controller;

import com.cn.mvc.annotation.MyAutowired;
import com.cn.mvc.annotation.MyController;
import com.cn.mvc.annotation.MyRequestMapping;
import com.cn.mvc.annotation.MySecurity;
import com.cn.mvc.pojo.User;
import com.cn.mvc.service.UserService;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@MyController
@MyRequestMapping("/user")
public class UserController {

    @MyAutowired
    private UserService userService;

    @MyRequestMapping("/getUser")
    @ResponseBody
    public User getUserById(String id, HttpServletResponse response) throws IOException {

        User user = userService.getUserById(id);
        System.out.println("user : " + user);
        response.getWriter().write("user:" + user);
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        return user;
    }
}
